package com.example.demo4.service.impl;

import com.example.demo4.entity.Fruit;
import com.example.demo4.service.AbstractStrategy;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.List;
/**
 * 普通
 */
public class PriceNormal extends AbstractStrategy {
    @Override
    public  BigDecimal acceptCash(List<Fruit> fruits){
        BigDecimal totalPrice = new BigDecimal(0) ;
        if(!CollectionUtils.isEmpty(fruits)){
            for(Fruit f : fruits){
                BigDecimal weight = f.getWeight();
                BigDecimal price = f.getPrice();
                totalPrice  =totalPrice.add(price.multiply(weight));
            }
        }
        return totalPrice.setScale(2,BigDecimal.ROUND_HALF_UP);
    }
}

